import 'dart:convert';
import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:city_pickers/city_pickers.dart';
import 'package:city_pickers/modal/result.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_picker/picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:image_picker/image_picker.dart';
import 'package:intl/intl.dart';
import 'package:roundcheckbox/roundcheckbox.dart';
import 'package:taonile/config/config.dart';
import 'package:taonile/entity/support_bank_entity.dart';

import '../entity/apply_business_info_entity.dart';
import '../http/api.dart';
import '../http/web_path.dart';
import '../routers/routers.dart';
import '../utils/oss_upload_util.dart';

///
/// 入驻-附近商圈
///
class MyStoreToJoinStore extends StatefulWidget {
  String id;

  MyStoreToJoinStore({Key? key, this.id = ''}) : super(key: key);

  @override
  State<MyStoreToJoinStore> createState() => _MyStoreToJoinStoreState();
}

class _MyStoreToJoinStoreState extends State<MyStoreToJoinStore> {
  var storeName = '';
  var _area = '点击选择省市区';
  var province = '';
  var city = '';
  var area = '';
  var province_name = '';
  var city_name = '';
  var area_name = '';
  var address = '';
  var store_logo = '';
  var bankName = '点击选择所属行业';
  var bankId = '';
  var userName = '';
  var userIdNum = '';
  var idNumImg1 = '';
  var idNumImg2 = '';
  String isThreeForOne = '1';
  var businessLicense = '';
  var userCreditCode = '';
  String isBusinessLicense = '1';
  var period = '点击选择执照有效期限';
  String certificateImg = '';

  List<SupportBankData> banks = [];
  bool checkProtocol = true;

  @override
  void initState() {
    super.initState();
    getMenu();
    getdatas();
  }

  getdatas() async {
    if (widget.id.isEmpty) {
      return;
    }
    dynamic result = await Api.businessDetail();
    ApplyBusinessInfoEntity entity = ApplyBusinessInfoEntity.fromJson(result);
    setState(() {
      storeName = entity.data.name;
      _area = '${entity.data.province}-${entity.data.city}-${entity.data.area}';
      province = entity.data.provinceId;
      city = entity.data.cityId;
      area = entity.data.areaId;
      province_name = entity.data.province;
      city_name = entity.data.city;
      area_name = entity.data.area;
      address = entity.data.address;
      store_logo = entity.data.logo;
      bankName = entity.data.categoryName;
      bankId = entity.data.categoryId;
      userName = entity.data.occupantName;
      userIdNum = entity.data.occupantId;
      idNumImg1 = entity.data.frontPhoto;
      idNumImg2 = entity.data.backPhoto;
      isThreeForOne = entity.data.isCertificates == '1' ? '1' : '2';
      businessLicense = entity.data.licensePhoto;
      userCreditCode = entity.data.creditCode;
      isBusinessLicense = entity.data.validityType == '1' ? '1' : '2';
      period = entity.data.licenseTime;
      certificateImg = entity.data.sanitaryPermits;
    });
  }

  getMenu() async {
    dynamic result = await Api.applyBusinessCategoryList({
      'type': 'offline',
      'page': '1',
      'limit': '100',
      'id': '0',
    });
    SupportBankEntity entity = SupportBankEntity.fromJson(result);
    setState(() {
      banks.clear();
      banks.addAll(entity.data);
    });
  }

  confirmPost() async {
    FocusManager.instance.primaryFocus?.unfocus();
    if (storeName.isEmpty) {
      EasyLoading.showToast("请输入店铺名称");
      return;
    }
    if (_area == '点击选择省市区') {
      EasyLoading.showToast("请选择注册地区");
      return;
    }
    if (address.length < 5) {
      EasyLoading.showToast("请输入店铺详细地址");
      return;
    }
    if (store_logo.isEmpty) {
      EasyLoading.showToast("请上传门牌照片");
      return;
    }
    if (bankName == '点击选择所属行业') {
      EasyLoading.showToast("请选择所属行业");
      return;
    }
    if (userName.isEmpty) {
      EasyLoading.showToast("请输入入驻人姓名");
      return;
    }
    if (userIdNum.isEmpty) {
      EasyLoading.showToast("请输入入驻人身份证号码");
      return;
    }
    if (idNumImg1.isEmpty) {
      EasyLoading.showToast("请上传身份证头像面");
      return;
    }
    if (idNumImg2.isEmpty) {
      EasyLoading.showToast("请上传身份证国徽面");
      return;
    }
    if (businessLicense.isEmpty) {
      EasyLoading.showToast("请上传印业执照");
      return;
    }
    if (userCreditCode.isEmpty) {
      EasyLoading.showToast("请输入统一社会信用代码");
      return;
    }
    if (period == '点击选择执照有效期限') {
      EasyLoading.showToast("请选择执照有效期");
      return;
    }
    if (certificateImg.isEmpty) {
      EasyLoading.showToast("请上传卫生许可证");
      return;
    }

    if (!checkProtocol) {
      EasyLoading.showToast("请阅读并同意入驻协议");
      return;
    }

    var param = {
      'type': 'offline',
      'name': storeName,
      'province': province_name,
      'city': city_name,
      'area': area_name,
      'province_id': province,
      'city_id': city,
      'area_id': area,
      'address': address,
      'logo': store_logo,
      'category_id': bankId,
      'occupant_name': userName,
      'occupant_id': userIdNum,
      'front_photo': idNumImg1,
      'back_photo': idNumImg2,
      'is_certificates': isThreeForOne == '1' ? '1' : '0',
      'license_photo': businessLicense,
      'credit_code': userCreditCode,
      'validity_type': isBusinessLicense == '1' ? '1' : '0',
      'sanitary_permits': certificateImg,
      'license_time': period,
      'labels': '...',
    };

    dynamic result;
    if (widget.id.isNotEmpty) {
      //修改
      param['id'] = widget.id;
      result = await Api.applyBusinessUpdate(param);
    } else {
      //新提交
      result = await Api.applyBusiness(param);
    }

    var jsonResult = jsonDecode(jsonEncode(result));
    if (jsonResult['code'] == 1) {
      EasyLoading.showToast('申请提交成功，等待审核');
      Routes.router.pop(context, {'result': 1});
    }
  }

  getCityResult() async {
    // type 1
    Result? result = await CityPickers.showCityPicker(
      showType: ShowType.pca,
      context: context,
      height: 600.w,
      barrierOpacity: 0.5,
      theme: Theme.of(context).copyWith(),
    );
    if (result != null) {
      String str = '${result.provinceName}-${result.cityName}-${result.areaName}';
      province_name = result.provinceName!;
      city_name = result.cityName!;
      area_name = result.areaName!;
      province = result.provinceId!;
      city = result.cityId!;
      area = result.areaId!;
      setState(() {
        _area = str;
      });
    }
  }

  chooseImage(Function fun) async {
    final ImagePicker _picker = ImagePicker();
    final XFile? image = await _picker.pickImage(source: ImageSource.gallery);
    String? imgPah = image?.path;
    if (imgPah != null) {
      LogUtil.v(imgPah, tag: '选择的图片路径=');
      EasyLoading.show(status: 'loading...');
      String result = await UploadOss.upload(File(imgPah), fileType: UploadOss.getFileType(imgPah));
      LogUtil.v(result);
      fun(result);
      EasyLoading.dismiss();
    }
  }

  chooseBank(BuildContext context) async {
    Picker(
        adapter: PickerDataAdapter(
            pickerData: List.generate(banks.length, (index) => banks[index].name), isArray: false),
        height: 450.w,
        headerDecoration: BoxDecoration(
          color: Config.colorWhite,
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(20.w),
            topRight: Radius.circular(20.w),
          ),
        ),
        itemExtent: 70.w,
        confirmText: '确定',
        cancelText: '取消',
        columnPadding: EdgeInsets.all(15.w),
        onConfirm: (picker, list) {
          // LogUtil.v(SingletonManager.instance.orderCancelReason[list[0]]);
          setState(() {
            bankName = banks[list[0]].name;
            bankId = banks[list[0]].id;
          });
        }).showModal(context, backgroundColor: Colors.transparent);
  }

  showChooseDate() {
    DatePicker.showDatePicker(
      context,
      showTitleActions: true,
      minTime: DateTime(2023, 1, 1),
      maxTime: DateTime(2043, 1, 1),
      onChanged: (date) {},
      onConfirm: (date) {
        print('confirm $date');
        FocusManager.instance.primaryFocus?.unfocus();
        setState(() {
          String formattedDate = DateFormat('yyyy-MM-dd').format(date);
          period = formattedDate;
        });
      },
      currentTime: DateTime.now(),
      locale: LocaleType.zh,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Config.colorBg2,
        appBar: AppBar(
          title: Text('商圈入驻'),
          centerTitle: true,
        ),
        body: Container(
          width: double.infinity,
          height: double.infinity,
          margin: EdgeInsets.symmetric(vertical: 0.w, horizontal: 25.w),
          child: SingleChildScrollView(
            child: Column(
              children: [
                Container(
                  margin: EdgeInsets.only(top: 25.w),
                  width: double.infinity,
                  padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 20.w),
                  decoration: BoxDecoration(
                    color: (Config.colorWhite),
                    borderRadius: BorderRadius.circular(10.w),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        child: Text(
                          "填写基本信息",
                          style: TextStyle(fontSize: 26.sp),
                        ),
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            width: 140.w,
                            child: Text(
                              "店铺名称",
                              style: TextStyle(fontSize: 25.sp),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 30.w),
                          ),
                          Container(
                            width: 485.w,
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            child: TextField(
                              keyboardType: TextInputType.text,
                              textAlign: TextAlign.justify,
                              obscureText: false,
                              autofocus: false,
                              maxLength: 20,
                              maxLines: 1,
                              onChanged: (value) {
                                setState(() {
                                  storeName = value;
                                });
                              },
                              style: TextStyle(fontSize: 25.sp, color: Config.colorText1),
                              decoration: const InputDecoration(
                                hintStyle: TextStyle(color: Config.colorText3),
                                hintText: "请填写店铺名称",
                                counterText: '',
                                isDense: true,
                                border: InputBorder.none,
                                contentPadding: EdgeInsets.zero, //设置文本内容的Padding
                              ),
                              controller: TextEditingController.fromValue(
                                TextEditingValue(
                                  text: storeName,
                                  selection: TextSelection.fromPosition(
                                    TextPosition(
                                        // affinity: TextAffinity.downstream,
                                        offset: storeName.length),
                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            width: 140.w,
                            child: Text(
                              "注册地区",
                              style: TextStyle(fontSize: 25.sp),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 30.w),
                          ),
                          InkWell(
                            onTap: () {
                              getCityResult();
                            },
                            child: Container(
                              width: 450.w,
                              margin: EdgeInsets.symmetric(vertical: 5.w),
                              child: Text(
                                _area,
                                style: TextStyle(fontSize: 25.sp),
                              ),
                            ),
                          ),
                          Icon(
                            Icons.arrow_forward_ios,
                            size: 25.w,
                          ),
                        ],
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            width: 140.w,
                            child: Text(
                              "详细地址",
                              style: TextStyle(fontSize: 25.sp),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 30.w),
                          ),
                          Container(
                            width: 485.w,
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            child: TextField(
                              keyboardType: TextInputType.text,
                              textAlign: TextAlign.justify,
                              obscureText: false,
                              maxLength: 30,
                              autofocus: false,
                              maxLines: 1,
                              onChanged: (value) {
                                setState(() {
                                  address = value;
                                });
                              },
                              style: TextStyle(fontSize: 25.sp, color: Config.colorText1),
                              decoration: const InputDecoration(
                                hintStyle: TextStyle(color: Config.colorText3),
                                hintText: "请输入店铺详细地址",
                                counterText: '',
                                isDense: true,
                                border: InputBorder.none,
                                contentPadding: EdgeInsets.zero, //设置文本内容的Padding
                              ),
                              controller: TextEditingController.fromValue(
                                TextEditingValue(
                                  text: address,
                                  selection: TextSelection.fromPosition(
                                    TextPosition(
                                        // affinity: TextAffinity.downstream,
                                        offset: address.length),
                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Container(
                        child: Text(
                          "店铺门牌照上传",
                          style: TextStyle(fontSize: 26.sp),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 20.w, bottom: 10.w),
                        height: 300.w,
                        child: Stack(
                          children: [
                            CachedNetworkImage(
                              imageUrl: store_logo,
                              fit: BoxFit.fitHeight,
                              width: double.infinity,
                              height: 300.w,
                              errorWidget: (context, url, error) {
                                return Image.asset(
                                  'assets/images/bg_default_400.png',
                                  width: double.infinity,
                                  height: 300.w,
                                  fit: BoxFit.fill,
                                );
                              },
                            ),
                            Positioned(
                              bottom: 0,
                              child: InkWell(
                                onTap: () {
                                  chooseImage((result) {
                                    setState(() {
                                      store_logo = result;
                                    });
                                  });
                                },
                                child: Container(
                                  decoration: BoxDecoration(color: Color(0x8fffffff)),
                                  width: 660.w,
                                  height: 55.w,
                                  alignment: Alignment.center,
                                  child: Text(
                                    '上传/修改',
                                    style: TextStyle(color: Config.colorText1, fontSize: 20.w),
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Text(
                        "图片要求：\n图片清晰不变形，建议大小104px*104px",
                        style: TextStyle(fontSize: 23.sp, color: Config.colorText3),
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            width: 140.w,
                            child: Text(
                              "所属行业",
                              style: TextStyle(fontSize: 25.sp),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 30.w),
                          ),
                          InkWell(
                            onTap: () {
                              chooseBank(context);
                            },
                            child: Container(
                              width: 450.w,
                              margin: EdgeInsets.symmetric(vertical: 5.w),
                              child: Text(
                                bankName,
                                style: TextStyle(fontSize: 25.sp),
                              ),
                            ),
                          ),
                          Icon(
                            Icons.arrow_forward_ios,
                            size: 25.w,
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 25.w),
                  width: double.infinity,
                  padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 20.w),
                  decoration: BoxDecoration(
                    color: (Config.colorWhite),
                    borderRadius: BorderRadius.circular(10.w),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        child: Text(
                          "主体信息",
                          style: TextStyle(fontSize: 26.sp),
                        ),
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            width: 140.w,
                            child: Text(
                              "入驻人姓名",
                              style: TextStyle(fontSize: 25.sp),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 30.w),
                          ),
                          Container(
                            width: 485.w,
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            child: TextField(
                              keyboardType: TextInputType.text,
                              textAlign: TextAlign.justify,
                              obscureText: false,
                              maxLength: 20,
                              autofocus: false,
                              maxLines: 1,
                              onChanged: (value) {
                                setState(() {
                                  userName = value;
                                });
                              },
                              style: TextStyle(fontSize: 25.sp, color: Config.colorText1),
                              decoration: const InputDecoration(
                                hintStyle: TextStyle(color: Config.colorText3),
                                hintText: "请填写入驻人姓名",
                                counterText: '',
                                isDense: true,
                                border: InputBorder.none,
                                contentPadding: EdgeInsets.zero, //设置文本内容的Padding
                              ),
                              controller: TextEditingController.fromValue(
                                TextEditingValue(
                                  text: userName,
                                  selection: TextSelection.fromPosition(
                                    TextPosition(
                                        // affinity: TextAffinity.downstream,
                                        offset: userName.length),
                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            width: 140.w,
                            child: Text(
                              "身份证号码",
                              style: TextStyle(fontSize: 25.sp),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 30.w),
                          ),
                          Container(
                            width: 485.w,
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            child: TextField(
                              keyboardType: TextInputType.text,
                              textAlign: TextAlign.justify,
                              obscureText: false,
                              maxLength: 18,
                              autofocus: false,
                              maxLines: 1,
                              onChanged: (value) {
                                setState(() {
                                  userIdNum = value;
                                });
                              },
                              style: TextStyle(fontSize: 25.sp, color: Config.colorText1),
                              decoration: const InputDecoration(
                                hintStyle: TextStyle(color: Config.colorText3),
                                hintText: "请填写入住人身份证号码",
                                counterText: '',
                                isDense: true,
                                border: InputBorder.none,
                                contentPadding: EdgeInsets.zero, //设置文本内容的Padding
                              ),
                              controller: TextEditingController.fromValue(
                                TextEditingValue(
                                  text: userIdNum,
                                  selection: TextSelection.fromPosition(
                                    TextPosition(
                                        // affinity: TextAffinity.downstream,
                                        offset: userIdNum.length),
                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Container(
                        child: Text(
                          "身份证照片上传",
                          style: TextStyle(fontSize: 26.sp),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 20.w),
                        height: 300.w,
                        child: Stack(
                          children: [
                            CachedNetworkImage(
                              imageUrl: idNumImg1,
                              fit: BoxFit.fitHeight,
                              width: double.infinity,
                              height: 300.w,
                              errorWidget: (context, url, error) {
                                return Image.asset(
                                  'assets/images/bg_default_400.png',
                                  width: double.infinity,
                                  height: 300.w,
                                  fit: BoxFit.fill,
                                );
                              },
                            ),
                            Positioned(
                              bottom: 0,
                              child: InkWell(
                                onTap: () {
                                  chooseImage((result) {
                                    setState(() {
                                      idNumImg1 = result;
                                    });
                                  });
                                },
                                child: Container(
                                  decoration: BoxDecoration(color: Color(0x8fffffff)),
                                  width: 660.w,
                                  height: 55.w,
                                  alignment: Alignment.center,
                                  child: Text(
                                    '上传/修改',
                                    style: TextStyle(color: Config.colorText1, fontSize: 20.w),
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 20.w),
                        height: 300.w,
                        child: Stack(
                          children: [
                            CachedNetworkImage(
                              imageUrl: idNumImg2,
                              fit: BoxFit.fitHeight,
                              width: double.infinity,
                              height: 300.w,
                              errorWidget: (context, url, error) {
                                return Image.asset(
                                  'assets/images/bg_default_400.png',
                                  width: double.infinity,
                                  height: 300.w,
                                  fit: BoxFit.fill,
                                );
                              },
                            ),
                            Positioned(
                              bottom: 0,
                              child: InkWell(
                                onTap: () {
                                  chooseImage((result) {
                                    setState(() {
                                      idNumImg2 = result;
                                    });
                                  });
                                },
                                child: Container(
                                  decoration: BoxDecoration(color: Color(0x8fffffff)),
                                  width: 660.w,
                                  height: 55.w,
                                  alignment: Alignment.center,
                                  child: Text(
                                    '上传/修改',
                                    style: TextStyle(color: Config.colorText1, fontSize: 20.w),
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            child: Text(
                              "营业执照是否三证合一",
                              style: TextStyle(fontSize: 25.sp),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 0.w),
                          ),
                          Flexible(
                            child: RadioListTile(
                              value: '1',
                              dense: true,
                              title: Text(
                                '是',
                                style: TextStyle(fontSize: 25.w),
                              ),
                              groupValue: isThreeForOne,
                              onChanged: (value) {
                                setState(() {
                                  isThreeForOne = '1';
                                });
                              },
                            ),
                          ),
                          Flexible(
                            child: RadioListTile(
                              value: '2',
                              dense: true,
                              title: Text(
                                '否',
                                style: TextStyle(fontSize: 25.w),
                              ),
                              groupValue: isThreeForOne,
                              onChanged: (value) {
                                setState(() {
                                  isThreeForOne = '2';
                                });
                              },
                            ),
                          ),
                        ],
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Container(
                        child: Text(
                          "营业执照上传",
                          style: TextStyle(fontSize: 26.sp),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 20.w, bottom: 10.w),
                        height: 300.w,
                        child: Stack(
                          children: [
                            CachedNetworkImage(
                              imageUrl: businessLicense,
                              fit: BoxFit.fitHeight,
                              width: double.infinity,
                              height: 300.w,
                              errorWidget: (context, url, error) {
                                return Image.asset(
                                  'assets/images/bg_default_400.png',
                                  width: double.infinity,
                                  height: 300.w,
                                  fit: BoxFit.fill,
                                );
                              },
                            ),
                            Positioned(
                              bottom: 0,
                              child: InkWell(
                                onTap: () {
                                  chooseImage((result) {
                                    setState(() {
                                      businessLicense = result;
                                    });
                                  });
                                },
                                child: Container(
                                  decoration: BoxDecoration(color: Color(0x8fffffff)),
                                  width: 660.w,
                                  height: 55.w,
                                  alignment: Alignment.center,
                                  child: Text(
                                    '上传/修改',
                                    style: TextStyle(color: Config.colorText1, fontSize: 20.w),
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Text(
                        "要求：\n请提供经营者姓名和入驻人一致的个体工商户营业执照；否则无法审核通过；",
                        style: TextStyle(fontSize: 23.sp, color: Config.colorText3),
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            width: 200.w,
                            child: Text(
                              "统一社会信用代码",
                              style: TextStyle(fontSize: 25.sp),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 30.w),
                          ),
                          Container(
                            width: 430.w,
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            child: TextField(
                              keyboardType: TextInputType.text,
                              textAlign: TextAlign.justify,
                              obscureText: false,
                              maxLength: 18,
                              autofocus: false,
                              maxLines: 1,
                              onChanged: (value) {
                                setState(() {
                                  userCreditCode = value;
                                });
                              },
                              style: TextStyle(fontSize: 25.sp, color: Config.colorText1),
                              decoration: const InputDecoration(
                                hintStyle: TextStyle(color: Config.colorText3),
                                hintText: "请填写18位数字或字母",
                                counterText: '',
                                isDense: true,
                                border: InputBorder.none,
                                contentPadding: EdgeInsets.zero, //设置文本内容的Padding
                              ),
                              controller: TextEditingController.fromValue(
                                TextEditingValue(
                                  text: userCreditCode,
                                  selection: TextSelection.fromPosition(
                                    TextPosition(
                                        // affinity: TextAffinity.downstream,
                                        offset: userCreditCode.length),
                                  ),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            child: Text(
                              "营业执照有效期",
                              style: TextStyle(fontSize: 25.sp),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 0.w),
                          ),
                          Flexible(
                            child: RadioListTile(
                              value: '1',
                              dense: true,
                              title: Text(
                                '固定期限',
                                style: TextStyle(fontSize: 25.w),
                              ),
                              groupValue: isBusinessLicense,
                              onChanged: (value) {
                                setState(() {
                                  isBusinessLicense = '1';
                                });
                              },
                            ),
                          ),
                          Flexible(
                            child: RadioListTile(
                              value: '2',
                              dense: true,
                              title: Text(
                                '长期',
                                style: TextStyle(fontSize: 25.w),
                              ),
                              groupValue: isBusinessLicense,
                              onChanged: (value) {
                                setState(() {
                                  isBusinessLicense = '2';
                                });
                              },
                            ),
                          ),
                        ],
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            margin: EdgeInsets.symmetric(vertical: 5.w),
                            width: 200.w,
                            child: Text(
                              "营业执照有效期",
                              style: TextStyle(fontSize: 25.sp),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 30.w),
                          ),
                          InkWell(
                            onTap: () {
                              showChooseDate();
                            },
                            child: Container(
                              width: 380.w,
                              margin: EdgeInsets.symmetric(vertical: 5.w),
                              child: Text(
                                period,
                                style: TextStyle(fontSize: 25.sp),
                              ),
                            ),
                          ),
                          Icon(
                            Icons.arrow_forward_ios,
                            size: 25.w,
                          ),
                        ],
                      ),
                      Divider(
                        color: Config.colorDivider,
                        height: 40.w,
                        thickness: 2.w,
                      ),
                      Container(
                        child: Text(
                          "请上传卫生许可证",
                          style: TextStyle(fontSize: 26.sp),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 20.w, bottom: 10.w),
                        height: 300.w,
                        child: Stack(
                          children: [
                            CachedNetworkImage(
                              imageUrl: certificateImg,
                              fit: BoxFit.fitHeight,
                              width: double.infinity,
                              height: 300.w,
                              errorWidget: (context, url, error) {
                                return Image.asset(
                                  'assets/images/bg_default_400.png',
                                  width: double.infinity,
                                  height: 300.w,
                                  fit: BoxFit.fill,
                                );
                              },
                            ),
                            Positioned(
                              bottom: 0,
                              child: InkWell(
                                onTap: () {
                                  chooseImage((result) {
                                    setState(() {
                                      certificateImg = result;
                                    });
                                  });
                                },
                                child: Container(
                                  decoration: BoxDecoration(color: Color(0x8fffffff)),
                                  width: 660.w,
                                  height: 55.w,
                                  alignment: Alignment.center,
                                  child: Text(
                                    '上传/修改',
                                    style: TextStyle(color: Config.colorText1, fontSize: 20.w),
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Text(
                        "要求：\n图片清晰不变形；",
                        style: TextStyle(fontSize: 23.sp, color: Config.colorText3),
                      ),
                    ],
                  ),
                ),
                Container(
                    margin: EdgeInsets.only(top: 40.w),
                    width: double.infinity,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        RoundCheckBox(
                            size: 15,
                            checkedWidget: const Icon(
                              Icons.check,
                              color: Colors.white,
                              size: 10,
                            ),
                            checkedColor: Config.colorMain,
                            uncheckedColor: Config.colorBg,
                            border: Border.all(
                                color: checkProtocol ? Config.colorMain : Config.colorText3,
                                width: 1),
                            isChecked: checkProtocol,
                            onTap: (selected) {
                              checkProtocol = selected!;
                              setState(() {});
                            }),
                        Padding(
                          padding: EdgeInsets.all(6.w),
                        ),
                        Text(
                          "我已阅读并同意",
                          style: TextStyle(
                            color: Config.colorText2,
                            fontSize: 26.sp,
                          ),
                        ),
                        InkWell(
                          onTap: () {
                            Routes.navigateTo(context, Routes.webView, params: {
                              'pageTitle': '淘你乐商家入驻协议',
                              'webUrl': '${Config.webUrl}${WebPath.storeApplyProtocol}'
                            });
                          },
                          child: Text(
                            "《淘你乐商家入驻协议》",
                            style: TextStyle(
                              color: Config.colorMain,
                              fontSize: 26.sp,
                            ),
                          ),
                        ),
                      ],
                    )),
                Container(
                  width: 750.w,
                  height: 100.w,
                  padding: EdgeInsets.symmetric(vertical: 8.w, horizontal: 8.w),
                  margin: EdgeInsets.only(top: 15.w),
                  child: ElevatedButton(
                    clipBehavior: Clip.antiAlias,
                    onPressed: () => {confirmPost()},
                    style: ElevatedButton.styleFrom(shape: const StadiumBorder()),
                    child: Text(widget.id.isEmpty ? '确认申请' : '确认修改申请'),
                  ),
                ),
              ],
            ),
          ),
        ));
  }
}
